#pragma once
#include "state_machine.h"

class AttrTreeNodeHead : public ui::TreeNode
{
public:
	virtual void OnClickItem() override;
	virtual void SetExpand(bool bExpand) override;
	
	void Reset();
};

class AttrTreeNodeGrid : public ui::TreeNode
{
public:
	bool InitNodeGrid();
	bool InsertAttr(const ui::ContrlAttrVistorItem& attr);
	bool OnGridTextChanged(ui::EventArgs *args);
	void SetControl(ui::Control* pControl) { m_pControl = pControl; };

	void Reset();
public:
	ui::Grid *m_pGrid;
	ui::Control *m_pControl{ nullptr };
	ui::AttrOfClass m_Visitor;
};

class AttrTree : public ui::TreeView, public IStateReceiver
{
public:
	AttrTree();
	virtual ~AttrTree();
	
	bool SelectControl(Control *control);

	/*ui::TreeNode *FindNodeByDataId(std::string id);
	ui::TreeNode *FindNodeByDataId(ui::TreeNode *parentNode, std::string id);*/
	virtual bool DoStateEvent(std::shared_ptr<StateEvent> event) override;

protected:
	bool Reset();

	bool RollBackTo(int index);
private:

	Control *m_pControl{ nullptr };

	std::vector<std::pair<AttrTreeNodeHead*, AttrTreeNodeGrid*>> m_vecPairNode;
	int m_nVecIndex{ -1 };
};

